package com.sl.biz.modular.thread.dao.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.annotation.InterceptorIgnore;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.conditions.update.LambdaUpdateChainWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sl.biz.modular.thread.dao.domain.dto.ProcessThreadConfigDTO;
import com.sl.biz.modular.thread.dao.domain.entity.ProcessThreadConfigDO;
import com.sl.biz.modular.thread.dao.mapper.ProcessThreadConfigMapper;
import com.sl.biz.modular.thread.dao.service.ProcessThreadConfigDaoService;
import com.sl.common.enums.CommonDsiableFlagEnum;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@RequiredArgsConstructor
public class ProcessThreadConfigDaoServiceImpl extends ServiceImpl<ProcessThreadConfigMapper, ProcessThreadConfigDO> implements ProcessThreadConfigDaoService {

    @InterceptorIgnore(tenantLine = "true")
    @Override
    public List<ProcessThreadConfigDTO> queryEnabledList() {
        LambdaQueryWrapper<ProcessThreadConfigDO> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(ProcessThreadConfigDO::getDisableFlag, CommonDsiableFlagEnum.ENABLE_FLAG.getCode());
        List<ProcessThreadConfigDO> list = baseMapper.selectList(wrapper);
        return BeanUtil.copyToList(list, ProcessThreadConfigDTO.class);
    }

    @Override
    public Boolean setStatusFlag(ProcessThreadConfigDO assertUserUse) {
        LambdaUpdateChainWrapper<ProcessThreadConfigDO> chainWrapper = new LambdaUpdateChainWrapper<>(baseMapper);
        chainWrapper.eq(ProcessThreadConfigDO::getId, assertUserUse.getId());
        chainWrapper.set(ProcessThreadConfigDO::getDisableFlag, assertUserUse.getDisableFlag());
        boolean ret = chainWrapper.update();
        return ret;
    }

    @Override
    public List<ProcessThreadConfigDTO> queryList(ProcessThreadConfigDO processThreadConfig) {
        LambdaQueryWrapper<ProcessThreadConfigDO> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(ObjectUtil.isNotNull(processThreadConfig.getDisableFlag()),ProcessThreadConfigDO::getDisableFlag, CommonDsiableFlagEnum.ENABLE_FLAG.getCode());
        List<ProcessThreadConfigDO> list = baseMapper.selectList(wrapper);
        return BeanUtil.copyToList(list, ProcessThreadConfigDTO.class);
    }
}
